package cn.edu.zafu.bigdata.cdn;

import java.util.List;

public class GenericMaxFinder {
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        T max = list.get(0);
        for (T item : list) {
            if (item.compareTo(max) > 0) {
                max = item;
            }
        }
        return max;
    }
    public static void main(String[] args) {

        List<Integer> integerList = List.of(3, 5, 1, 4, 2);
        Integer maxInteger = findMax(integerList);
        System.out.println("The maximum integer is: " + maxInteger);
        List<String> stringList = List.of("apple", "banana", "cherry", "date");
        String maxString = findMax(stringList);
        System.out.println("The maximum string is: " + maxString);
    }
}
 